package com.core.dao.mybatismysql;

import com.core.bean.Goods;
import com.core.dao.IGoodsDao;
import com.core.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class GoodsDao implements IGoodsDao {
    @Override
    public int add(Goods entity) throws Exception {
        SqlSession session = MybatisUtils.getSession();
        IGoodsDao iGoodsDao = session.getMapper(IGoodsDao.class);
        int add = iGoodsDao.add(entity);
        return add;
    }

    @Override
    public int remove(String id) throws Exception {
        SqlSession session = MybatisUtils.getSession();
        IGoodsDao iGoodsDao = session.getMapper(IGoodsDao.class);
        return iGoodsDao.remove(id);
    }

    @Override
    public int modify(Goods entity) throws Exception {
        SqlSession session = MybatisUtils.getSession();
        IGoodsDao iGoodsDao = session.getMapper(IGoodsDao.class);
        return iGoodsDao.modify(entity);
    }
    @Override
    public Goods findEntityById(String id) throws Exception {
        SqlSession session = MybatisUtils.getSession();
        IGoodsDao iGoodsDao = session.getMapper(IGoodsDao.class);
        Goods goods = iGoodsDao.findEntityById(id);
        return goods;
    }

    @Override
    public List<Goods> findByPropertyId(String pid) {
        SqlSession session = MybatisUtils.getSession();
        IGoodsDao iGoodsDao = session.getMapper(IGoodsDao.class);
        return iGoodsDao.findByPropertyId(pid);
    }
}
